{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 1. Download YouTube videos 🔗📥🎥 \n",
    "(or automatically skip if you have placed the video in the root directory)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import glob\n",
    "if not glob.glob(\"*.mp4\") + glob.glob(\"*.webm\"):\n",
    "    from core.step1_ytdlp import download_video_ytdlp\n",
    "    url = input(\"🔗 Please enter the youtube URL of the video:\")\n",
    "    download_video_ytdlp(url, save_path='./')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 2. Whisper Speech-to-Text 🎤🔀📝"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Importing the dtw module. When using in academic works please cite:\n",
      "  T. Giorgino. Computing and Visualizing Dynamic Time Warping Alignments in R: The dtw Package.\n",
      "  J. Stat. Soft., doi:10.18637/jss.v031.i07.\n",
      "\n",
      "🚀 Starting Whisper...\n",
      "🖥️  ASR Device: cpu\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 98%|█████████▊| 134149/137149 [10:41<00:14, 209.13frames/s]\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "🗑️ Temporary audio file Italy Travel Vlog： exploring Florence, Tuscany and Venice (2022)_temp.mp3 has been deleted.\n",
      "📊 Excel file has been saved to output/log/cleaned_chunks.xlsx\n"
     ]
    }
   ],
   "source": [
    "import glob, os\n",
    "video_file = (glob.glob(\"*.mp4\") + glob.glob(\"*.webm\"))[0]\n",
    "\n",
    "if not os.path.exists(\"output/log/cleaned_chunks.xlsx\"):\n",
    "    from core.step2_whisper_stamped import transcript\n",
    "    transcript(video_file)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 3. Split Sentences using both NLP and LLM 🤖🧠✂️"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "if not os.path.exists(\"output/log/sentence_splitbymark.txt\"):\n",
    "    from core.step3_1_spacy_split import split_by_spacy\n",
    "    split_by_spacy()\n",
    "\n",
    "from core.step3_2_splitbymeaning import split_sentences_by_meaning\n",
    "split_sentences_by_meaning()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 4. Summarize and Translate 🌐🔄📚"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from core.step4_1_summarize import get_summary\n",
    "get_summary()\n",
    "\n",
    "from core.step4_2_translate_all import translate_all\n",
    "translate_all()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 5. Trim Excessively Long Subtitles According to Length Criteria 📏✂️📄"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from core.step5_splitforsub import split_for_sub_main\n",
    "split_for_sub_main()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 6. Align to Generate Timeline and Final Subtitles ⏱️📅🎬"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from core.step6_generate_final_timeline import align_timestamp_main\n",
    "align_timestamp_main()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 7. Merge subtitles to video 🎬🔀🎥"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from core.step7_merge_sub_to_vid import merge_subtitles_to_video\n",
    "merge_subtitles_to_video()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## The next part is the dubbing section, please download the one-click integration package if needed"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 8. extract"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# from core.step8_extract_refer_audio import step8_main\n",
    "# import glob  \n",
    "# input_video = (glob.glob(\"*.mp4\") + glob.glob(\"*.webm\"))[0]\n",
    "# step8_main(input_video)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### core\\step9_generate_audio_task.py"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# import os\n",
    "# if not os.path.exists(\"output/audio/sovits_tasks.xlsx\"):\n",
    "#     from core.step9_generate_audio_task import step9_main\n",
    "#     step9_main()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### core\\step10_generate_audio.py\n",
    "This step is likely to go wrong due to the excessive length of the subtitles. Please modify the corresponding subtitles according to the prompts after running, and then rerun."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# from core.step10_generate_audio import process_sovits_tasks\n",
    "# process_sovits_tasks()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### core\\step11_merge_audio_to_vid.py"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# from core.step11_merge_audio_to_vid import merge_all_audio\n",
    "# merge_all_audio()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Whisper",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
